﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OALPTool
{
    public partial class Form9 : Form
    {
        public Form9()
        {
            InitializeComponent();
        }

        private void Form9_Load(object sender, EventArgs e)
        {
            //添加列
            DataGridViewTextBoxColumn tcDM = new DataGridViewTextBoxColumn();
            tcDM.HeaderText = "班级代码";
            tcDM.Name = "DM";
            //tcDM.DataPropertyName = "DM";
            tcDM.ReadOnly = true;
            //tcDM.SortMode = DataGridViewColumnSortMode.NotSortable;
            //tcDM.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgv.Columns.Add(tcDM);

            DataGridViewTextBoxColumn tcMC = new DataGridViewTextBoxColumn();
            tcMC.HeaderText = "班级名称";
            tcMC.Name = "MC";
            tcMC.ReadOnly = true;
            dgv.Columns.Add(tcMC);
            DataGridViewTextBoxColumn tcNan = new DataGridViewTextBoxColumn();
            tcNan.HeaderText = "男";
            tcNan.Name = "Nan";
            tcNan.ReadOnly = true;
            dgv.Columns.Add(tcNan);
            DataGridViewTextBoxColumn tcNv = new DataGridViewTextBoxColumn();
            tcNv.HeaderText = "女";
            tcNv.Name = "Nv";
            tcNv.ReadOnly = true;
            dgv.Columns.Add(tcNv);
            //增加TreeView
            TreeView tv = new TreeView();
            TreeNode tnDM = new TreeNode("班级代码");
            tv.Nodes.Add(tnDM);
            TreeNode tnMC = new TreeNode("班级名称");
            tv.Nodes.Add(tnMC);
            TreeNode tnSex = new TreeNode("性别");
            tv.Nodes.Add(tnSex);
            TreeNode tnNan = new TreeNode("男");
            tnSex.Nodes.Add(tnNan);
            TreeNode tnNv = new TreeNode("女");
            tnSex.Nodes.Add(tnNv);
            dgv.ColumnTreeView = new TreeView[] { tv };
            //设置其他属性
            dgv.AutoGenerateColumns = false;                                    //不自动增加列
            dgv.RowHeadersVisible = false;                                      //行头不可见
            dgv.AllowUserToAddRows = false;
            dgv.RowTemplate.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            dgv.ColumnDeep = 2;
            dgv.CellHeight = 25;
            dgv.ColumnHeadersHeight = 50;
            dgv.RefreshAtHscroll = true;

            dgv.Rows.Add();   //添加行
            dgv.Rows[0].Cells["DM"].Value = "2003001";
            dgv.Rows[0].Cells["MC"].Value = "网络一班"; ;
            dgv.Rows[0].Cells["Nan"].Value = "26人";
            dgv.Rows[0].Cells["Nv"].Value = "18人";

            dgv.MergeColumnNames.Add("Column11");//Column11需要合并单元格的列





        }
    }
}
